/**
 * create by young (young2f@outlook.com) on 2020/12/4
 * 库存批准记录
 */
'use strict';
const model = require('../base/modelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {

    lotType: {
      type: String, _type: 'string', title: '批次类型', required: true, enableArea: [
        'table',
        'detail',
        'search'
      ], options: [ '采购入库', '订单退货入库' ]
    },

    pmLotId: { type: 'string', _type: 'string', title: '物料采购批次编码', required: true, enableArea: [] },
    division: { type: 'string', _type: 'string', title: '采购公司', required: true, enableArea: [] },
    lotCode: {
      type: 'string', _type: 'string', title: '批次编码', required: true, enableArea: []
    },

    procureOrderCode: {
      type: 'string',
      _type: 'string',
      table: 'material',
      title: '采购单编码',
      required: true,
      disabled: true,
      enableArea: [
        'table',
        'detail',
        'search'
      ]
    },
    price: {
      type: 'number', _type: 'number', title: '含13单价', enableArea: [
        'table', 'input',
        'detail',
      ], default: 0
    },

    // materialBody: {
    //   type: 'object', _type: 'object', table: 'material', title: '物料信息', required: true, enableArea: []
    // },
    vendor: {
      type: 'string', _type: 'string', title: '供应商名称', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    vendorCode: {
      type: 'string', _type: 'string', title: '供应商编码', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    name: {
      type: 'string', _type: 'search', table: 'material', title: '物料名称', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    code: {
      type: 'string', _type: 'search', table: 'material', title: '物料编码', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    subcategory: {
      type: 'string',
      _type: 'string',
      title: '小类',
      enableArea: [ 'table', 'input', 'detail', 'search' ]
    },
    spec: {
      type: 'string', _type: 'string', title: '规格', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    number: {
      type: 'string', _type: 'string', title: '物料编号', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    type: {
      type: 'string', _type: 'string', title: '物料类型', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    count: {
      type: Number, _type: 'number', title: '采购数量', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    procureShippingFee: { type: Number, _type: 'number', title: '运费', enableArea: [ 'table', 'search' ], },
    checkInfo: {
      type: 'object', _type: 'object', table: 'material', title: '检查信息', enableArea: []
    },
    target: { type: 'string', inputType: 'string', title: '去向', enableArea: [ 'table', 'input', 'detail', ], },
    customer: { type: 'string', inputType: 'string', title: '去向客户', enableArea: [ 'table', 'input', 'detail', ], },
    customerProject: { type: 'string', inputType: 'string', title: '客户项目', enableArea: [ 'table', 'input', 'detail', ], },
    inboundCount: {
      type: Number, _type: 'number', title: '入库数量', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    inboundDate: {
      type: Date, _type: 'date', title: '入库日期', enableArea: [
        'table',
        'detail',
        'search'
      ]
    },
    usedCount: {
      type: Number, _type: 'number', title: '占用数量', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ], default: 0
    },
    discardCount: {
      type: Number, _type: 'number', title: '报废数量', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ], default: 0
    },
    fileList: {
      type: Array, _type: 'array', title: '附件', enableArea: []
    },

  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('InboundLot', _schema);
};
